﻿@page "/DLLDisplay"

@using Hangfire_Demo.Data
@inject DLLService dllDisplayService

<h3>Task</h3>

<p>组件数据来自 ..\plugin \各项目文件夹\ project.config </p>
<p>周期任务由调度数据表持久化保存 <a class="btn btn-primary" href="/hangfire" target="_blank">调度面板</a></p>

<button class="btn btn-primary" @onclick="RefeshPlugin">项目刷新</button>
<button class="btn btn-primary" @onclick="AddRecurringJob">全部项目周期执行</button>

@if (projects == null)
{
    <p><em>Loading...</em></p>
}
else
{
    <table class="table" style="width: 100%;">
        <thead>
            <tr>
                <th style="width: 5%;">项目</th>
                <th style="width: 5%;">文件</th>
                @* <th>文件日期</th> *@
                <th style="width: 40%;">项目上传API</th>
                <th style="width: 20%;">间隔时间</th>
                <th style="width: 10%;">时间单位</th>
                <th style="width: 20%;"> 按钮</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var pp in projects)
            {
                <tr>
                    <td >@pp.childProject.Name</td>
                    <td >@pp.dllFileObject.Name</td>
                    @* <td>@pp.dllFileObject.CreationTime</td> *@
                    <td><input @bind="pp.childProject.upLoadUrl" style="width: 100%;height: 30px;" /></td>
                    <td><input @bind="pp.childProject.planPeriod" style="width: 20%;height: 30px;" /></td>

                    <td style ="width: 10%;">
                        <select class="btn btn-primary"  @bind="pp.childProject.planPeriodUnit">
                        <option value="second">second</option>
                        <option value="minute">minute</option>
                        <option value="hour">hour</option>
                    </select>
                    </td>
                    <td style="width: 20%;">
                        <button class="btn btn-primary" @onclick="()=>SaveOne(pp)">保存</button>
                        <button class="btn btn-primary" @onclick="()=>ExcuteOneTest(pp)">单次执行</button>
                        </td>
                </tr>
            }
        </tbody>
    </table>
}

@code {
    private projectDto[] projects;

    protected override async Task OnInitializedAsync()
    {
        projects = await dllDisplayService.GetProjectListAsync(DateTime.Now);
    }

    public void RefeshPlugin()
    {
        dllDisplayService.RefeshPlugin();
    }

    public void ExcuteOneTest(projectDto projectDtoRow)
    {
        dllDisplayService.ExcuteOneTest(projectDtoRow);
    }

    public void SaveOne(projectDto projectDtoRow)
    {
        dllDisplayService.SaveOne(projectDtoRow);
    }

    public void AddRecurringJob()
    {
        dllDisplayService.AddRecurringJob();
    }
}
